<!--
 * @Author: Wushiqi
 * @Descripttion: 
 * @Date: 2021-04-13 11:31:21
 * @LastEditor: Wushiqi
 * @LastEditTime: 2021-04-13 13:43:48
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // 6: [[1, 2, 3]]
    // 10: [[1, 2, 3, 4]]
    // 15: [[1, 2, 3, 4, 5], [4, 5, 6], [7, 8]]
    // 先找到中间数，若不整除，则向上取整
    function fn(n) {
      let res = []
      const middleData = Math.ceil(n/2)
      for (let i = 1; i < middleData; i++) {
        let count = 0
        for (let j = i;;j++) {
          if (count === n) {
            res.push([...getArray(i, j)])
            break
          } else if (j > n) {
            break
          } else {
            count += j
            continue
          }
        }
      }
      return res
    }
    function getArray(n, m) {
      let res = []
      for (let i = n; i < m; i++) {
        res.push(i)
      }
      return res
    }
    console.log(fn(6)); // [[1, 2, 3]]
    console.log(fn(10)); // [[1, 2, 3, 4]]
    console.log(fn(11)); // [[5, 6]]
    console.log(fn(15)); // [[1, 2, 3, 4, 5], [4, 5, 6], [7, 8]]
    console.log(fn(21)); // [[1, 2, 3, 4, 5, 6], [6, 7, 8], [10, 11]]
  </script>
</body>
</html>